package com.mashibing.test.singleton;

import java.util.concurrent.TimeUnit;

/**
 * @author: mayu
 * @date: 2021年05月18日 16:36
 * 懒汉式
 */
public class S2 {
    private static S2 INSTANCE = null;

    private S2() {
    }

    public static S2 getInstance() {
        if (INSTANCE == null) {
            try {
                TimeUnit.MILLISECONDS.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            INSTANCE = new S2();
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "：" + S2.getInstance().hashCode());
            }).start();
        }
    }
}
